import tkinter as tk
import logging
from modules.main_window import MainWindow

# 配置日志
def setup_logging():
    log_dir = "logs"
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        handlers=[
            logging.FileHandler(os.path.join(log_dir, 'ssh_tool.log'), encoding='utf-8'),
            logging.StreamHandler()
        ]
    )

if __name__ == "__main__":
    import os
    
    # 设置日志
    setup_logging()
    logger = logging.getLogger(__name__)
    
    # 创建主窗口
    root = tk.Tk()
    root.option_add("*Font", "Arial 10")
    
    try:
        app = MainWindow(root)
        # 添加窗口关闭事件处理，确保所有连接都已关闭
        root.protocol("WM_DELETE_WINDOW", lambda: (app.server_connection.close_all_connections(), root.destroy()))
        logger.info("SSH工具启动成功")
        root.mainloop()
    except Exception as e:
        logger.error(f"程序启动失败: {e}", exc_info=True)
        raise  